Skip to main content

My Promise

· One min read
class MyPromise {
constructor(executor) {
this.executor = executor;
this.resolve = this.resolve.bind(this);
this.executor(this.resolve);

process.nextTick(() => {
this.callback(this.result);
});
}

then(callback) {
this.callback = callback;
}

resolve(result) {
this.result = result;
}
}

function foo() {
new MyPromise((resolve) => resolve("done")).then((res) =>
console.log(`Returned ${res}`)
);
}

foo();